﻿@using MvcApplication1.Models;
@{
    ViewBag.Title = "UserAccountManage";
}

<h2>账户管理</h2>
<script type="text/javascript">
    //页面URL
    var usermanageurl = '@Url.Action("UserAccountManage")';
   
    //搜索参数
    $('#username_search').val('@ViewBag.username_search');
    var searchparam = 'username=' + '@ViewBag.username_search';
    var pageparam = 'page=' + '@ViewBag.pagenumber';
    //generate url incluing the parameters for searching, sorting and paging 
    function generateUrl() {
        return usermanageurl + '?' + searchparam + '&' + pageparam;
    }
    //---------paging function----------------------------
    function firstpage() {
        pageparam = 'page=1';
        window.location = generateUrl();
    }
    function lastpage(pagecount) {
        pageparam = 'page=' + pagecount;
        window.location = generateUrl();
    }
    function prevpage(pagenumber) {
        pageparam = 'page=' + (pagenumber - 1);
        window.location = generateUrl();
    }
    function nextpage(pagenumber) {
        pageparam = 'page=' + (pagenumber + 1);
        window.location = generateUrl();
    }
    //-----------paging function-----------------------------

</script>
<div>
    <ul>
        <li>@Html.ActionLink("品牌管理","Index")</li><li>@Html.ActionLink("用户管理","UserAccountManage")</li>
    </ul>
</div>
@{
    int pagenumber = ViewBag.pagenumber;
    int pagecount = ViewBag.pagecount;
    <div><label>用户名搜索</label><input type="text" id="username_search" /><button id="btn_username_search">搜索</button><button id="clear_search">清除搜索</button></div>
    <table border="1">
            <thead>
                <tr>
                    <th>
                        <div>
                        用户名称
                        </div>
                    </th>
                    <th>
                        <div>
                        注册时间
                        </div>
                    </th>
                    <th>
                        上次登录
                    </th>
                    <th>
                        <div>
                        电子邮件
                        </div>
                    </th>
                </tr>
            </thead>
            @foreach (MvcApplication1.Models.User user in ViewBag.userlist)
            {
                <tr>
                    <td>@user.username</td>
                    <td>@user.creationdate</td>
                    <td>@user.lastlogin</td>
                    <td>@user.email</td>
                    <td>@Html.ActionLink("详细信息", "AdminEditUser", new { username=user.username })</td>
                </tr>    
            }
    </table>
}
@helper PageLink(int pagenumber, int pagecount)
    {
    <div id="pager">
        @if (pagenumber == 1)
        {
            <text>第一页 前一页 </text>
        }
        else
        {
            <a onclick="firstpage()">第一页</a>
            <a onclick="prevpage(@pagenumber)">前一页</a>
        }
        <span>当前第 @pagenumber 页 共 @pagecount 页</span>
        @if (pagenumber == pagecount)
        {
            <text>后一页 最后一页</text>
        }
        else
        {
            <a onclick="nextpage(@pagenumber)">后一页</a>
            <a onclick="lastpage(@pagecount)">最后一页</a>
        }
    </div>
}

<div id="gridbar">
    
    @PageLink(pagenumber, pagecount)
</div>
<script type="text/javascript">
    //executed after the document has loaded

    //-------searching----------------------------------------------
    $('#btn_username_search').click(function () {
        var username = $('#username_search').val();

        searchparam = 'username=' + username;
        window.location = generateUrl();
    });

    $('#clear_search').click(function () {
        searchparam = '';
        window.location = generateUrl();
    });
</script>